<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top: 10px;
  }
  .financial-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .flow-btn-export {
    margin-bottom: 10px;
    margin-top: -46px;
    float: right;
  }
  .sale-tag {
    width: 180px;
    height: 40px;
    font-size: 13px;
    text-align: center;
    line-height: 40px;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>财务流水</span>
    </div>
    <div class="line"></div>
    <financial-form
      :title="title"
      class="financial-form"
      @on-success-valid="handleSubmit">
    </financial-form>
    <btn-export :tableData="flowList" :tableTitle="columns" :title="title" class="flow-btn-export"></btn-export>
    <div>
      <div style="margin-left: 10px; margin-top: -15px;">
        <Tag style="margin-right: 15px" color="orange" class="sale-tag">总入账：{{flowSumData[flowSumData.length-1] ? flowSumData[flowSumData.length-1].income : '-'}}</Tag>
        <Tag color="volcano" class="sale-tag">总出帐：{{flowSumData[flowSumData.length-1] ? flowSumData[flowSumData.length-1].account : '-'}}</Tag>
      </div>
    </div>
    <Table
      class="table"
      :columns="columns"
      :data="historyData"
      border>
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import FinancialForm from '_c/financial-form'
import BtnExport from '_c/btn-export'
import TablePage from '_c/table-page'
export default {
  components: {
    FinancialForm,
    TablePage,
    BtnExport
  },
  data () {
    return {
      page: 1,
      title: '财务管理财务流水',
      postData: null,
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 80,
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        {
          title: '交易日期',
          key: 'ctime',
          // width: 200,
          align: 'center'
        },
        {
          title: '姓名',
          key: 'name',
          // width: 160,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.name ? params.row.name : '-')
          }
        },
        {
          title: '电话',
          key: 'phone',
          // width: 160,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.phone ? params.row.phone : '-')
          }
        },
        {
          title: '信息',
          key: 'des',
          // width: 160,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.des ? params.row.des : '-')
          }
        },
        {
          title: '消费类型',
          key: 'type',
          // width: 166,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.type === 0 ? '佣金充值' : params.row.type === 1 ? '服务费充值' : params.row.type === 2 ? '短信发送费用' : params.row.type === 3 ? '口碑结算' : params.row.type === 4 ? '到店结算' : params.row.type === 5 ? '成交结算' : '-')
          }
        },
        {
          title: '费用明细',
          key: 'money',
          // width: 160,
          align: 'center'
        }
      ]
    }
  },
  computed: {
    ...mapState({
      flowList: state => state.flow.flowList,
      flowSumData: state => state.flow.flowSumData,
      dataCount: state => state.flow.flowDataCount,
      historyData: state => state.flow.flowHistoryData,
      pageSize: state => state.flow.flowPageSize,
      row: state => state.flow.row
    })
  },
  methods: {
    ...mapActions([
      'getFlowList',
      'changeFlowPage',
      'changeFlowPageSize'
    ]),
    handleSubmit (playload) {
      this.postData = {
        ctime: playload.ctime,
        type: playload.type
      }
      this.getFlowList({
        ...this.postData,
        rows: this.rows
      })
    },
    changePage (index) {
      this.page = index
      this.changeFlowPage(index)
    },
    changePageSize (value) {
      this.changeFlowPageSize(value)
      this.changePage(this.page)
    }
  },
  created () {
    this.getFlowList({})
  }
}
</script>
